package com.org.oracle.controller;

import com.org.oracle.mongodb.entity.CircleContext;
import com.org.oracle.mongodb.entity.Comment;
import com.org.oracle.result.Result;
import com.org.oracle.service.CircleService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;



/**
 * @author suze
 * @date 2024/8/18
 * @time 20:38
 **/
@RestController
@RequestMapping("/circle")
public class CircleController {
    /***
     *@author suze
     *@date 2024-08-18
     *@time 22:07
     *@description 这一块是查 的接口
     */

    @Resource
    private CircleService circleService;
    //下面是各功能的接口
    //查-知识圈 查全部
    @GetMapping("/findAll")
    public Result find_all(){
        return Result.ok(circleService.find_all());
    }
    //根据标签查知识圈
    @GetMapping("/findByTag")
    public Result find_by_tag(@RequestParam("tag") String tag){
        return Result.ok(circleService.find_by_tag(tag));
    }
    //根据词汇搜索知识圈
    @GetMapping("/findByWord")
    public Result find_by_word(@RequestParam("word")String word){
        return Result.ok(circleService.find_by_word(word));
    }
    //查找用户已加入的知识圈
    @GetMapping("/findByUser")
    public Result find_by_user(@RequestHeader("uid")String uid){
        return Result.ok(circleService.find_by_user(uid));
    }

    /***
     *@author suze
     *@date 2024-08-18
     *@time 22:07
     *@description 这一块是用户与知识圈交互的接口
     */
    //用户加入知识圈
    @GetMapping("/joinCircle")
        public Result join_circle(@RequestHeader("uid")String uid,@RequestParam("circleId")String cid){
        return Result.ok(circleService.join_circle(uid,cid));
    }
    //用户发送手写笔记
    @PostMapping("/sendNote")
    public Result send_note(@RequestHeader("uid")String uid,@RequestBody CircleContext circleContext){
        return Result.ok(circleService.send_note(uid,circleContext));
    }
    //用户发送评论
    @GetMapping("/sendComment")
    public Result send_comment(@RequestHeader("uid")String uid,@RequestBody Comment comment){
        return Result.ok(circleService.send_comment(uid,comment));
    }
    //通过笔记id查看某笔记的评论详情
    @GetMapping("/findComment")
    public Result find_comment(@RequestParam("cmid") String cmid){
        return Result.ok(circleService.find_comment(cmid));
    }
    //用户回复评论
    @PostMapping("/replyComment")
    public Result reply_comment(@RequestHeader("uid")String uid,@RequestBody Comment comment) {
        Comment data = circleService.reply_comment(uid, comment);
        if (data != null) {
            return Result.ok(data);
        }
        return Result.fail("回复失败");
    }
}
